package cn.mdmm.controller.leavMessage;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.mdmm.common.MessageConstant;
import cn.mdmm.controller.BaseController;
import cn.mdmm.entity.leavMessage.LeavingMessageInfoModel;
import cn.mdmm.entity.response.ResponseBodyToOne;
import cn.mdmm.service.leavMessage.LeavingMessageInfoService;
import cn.modoumama.common.RequestUtils;
import cn.modoumama.common.exception.ServiceException;
import cn.modoumama.page.GridDataModel;
import cn.modoumama.page.Page;

@Controller
@RequestMapping(value="leavMessage")
public class LeavMessageController extends BaseController{
	
	@Autowired
	private LeavingMessageInfoService messageInfoService;
	
	@RequestMapping("toMessageInfo")
	public String toMessageInfo(HttpServletRequest request){
		
		return "leavMessage/list";
	}
	
	@RequestMapping("getMessageInfo")
	@ResponseBody
	public GridDataModel getMessageInfo(HttpServletRequest request,String userName){
		Page po = RequestUtils.getPage(request, "`Create_Time` DESC");
		po.getCondition().put("userName", userName);
		GridDataModel returnData = messageInfoService.findGridDataModelByCondition(po);
		return returnData;
	}
	
	@RequestMapping("toGetInfo")
	public String toGetInfo(HttpServletRequest request,Integer id){
		LeavingMessageInfoModel model = messageInfoService.findById(id);
		request.setAttribute("leavMessage", model);
		return  "leavMessage/info" ;
	}
	
	@RequestMapping(value = "delete")
	@ResponseBody
	public ResponseBodyToOne delete(HttpServletRequest request, HttpServletResponse response,Integer[] ids){
		ResponseBodyToOne responseBody = new ResponseBodyToOne();
		logger.debug("method: delete() ");
		try {
			messageInfoService.removeByIds(ids);
		} catch (Exception e) {
			throw new ServiceException(MessageConstant.SYSTEM_ERROR);
		}
		return responseBody;
	}
}
